🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / messaging / src / commonMain / kotlin / org / meshtastic / feature / messaging / component / FormattingToolbar.kt
Displaying Raw • Download
feature/messaging/src/commonMain/kotlin/org/meshtastic/feature/messaging/component/FormattingToolbar.kt bc5cf83df7fd6b405ffc521d7c3ed4e1f3e8271a (bc5cf83d) Text, 6.54 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.messaging.component
Tff7b72import T7ee787androidx.compose.foundation.layout.Arrangement
Tff7b72import T7ee787androidx.compose.foundation.layout.Row
Tff7b72import T7ee787androidx.compose.foundation.text.input.TextFieldState
Tff7b72import T7ee787androidx.compose.material3.AlertDialog
Tff7b72import T7ee787androidx.compose.material3.Icon
Tff7b72import T7ee787androidx.compose.material3.IconButton
Tff7b72import T7ee787androidx.compose.material3.OutlinedTextField
Tff7b72import T7ee787androidx.compose.material3.Text
Tff7b72import T7ee787androidx.compose.material3.TextButton
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.getValue
Tff7b72import T7ee787androidx.compose.runtime.mutableStateOf
Tff7b72import T7ee787androidx.compose.runtime.remember
Tff7b72import T7ee787androidx.compose.runtime.setValue
Tff7b72import T7ee787androidx.compose.ui.Modifier
Tff7b72import T7ee787androidx.compose.ui.graphics.vector.ImageVector
Tff7b72import T7ee787androidx.compose.ui.text.TextRange
Tff7b72import T7ee787androidx.compose.ui.unit.dp
Tff7b72import T7ee787org.jetbrains.compose.resources.stringResource
Tff7b72import T7ee787org.meshtastic.core.resources.Res
Tff7b72import T7ee787org.meshtastic.core.resources.cancel
Tff7b72import T7ee787org.meshtastic.core.resources.format_bold
Tff7b72import T7ee787org.meshtastic.core.resources.format_code
Tff7b72import T7ee787org.meshtastic.core.resources.format_italic
Tff7b72import T7ee787org.meshtastic.core.resources.format_link
Tff7b72import T7ee787org.meshtastic.core.resources.format_strikethrough
Tff7b72import T7ee787org.meshtastic.core.resources.insert
Tff7b72import T7ee787org.meshtastic.core.resources.insert_link_message
Tff7b72import T7ee787org.meshtastic.core.resources.insert_link_title
Tff7b72import T7ee787org.meshtastic.core.resources.insert_link_url_hint
Tff7b72import T7ee787org.meshtastic.core.ui.component.InlineStyle
Tff7b72import T7ee787org.meshtastic.core.ui.icon.Bold
Tff7b72import T7ee787org.meshtastic.core.ui.icon.Code
Tff7b72import T7ee787org.meshtastic.core.ui.icon.Italic
Tff7b72import T7ee787org.meshtastic.core.ui.icon.Link
Tff7b72import T7ee787org.meshtastic.core.ui.icon.MeshtasticIcons
Tff7b72import T7ee787org.meshtastic.core.ui.icon.Strikethrough
Tff7b72import T7ee787org.meshtastic.feature.messaging.FormattingResult
Tff7b72import T7ee787org.meshtastic.feature.messaging.insertDelimiters
Tff7b72import T7ee787org.meshtastic.feature.messaging.isMarkdownLink
Tff7b72import T7ee787org.meshtastic.feature.messaging.unwrapLink
Tff7b72import T7ee787org.meshtastic.feature.messaging.wrapSelection
Tff7b72import T7ee787org.meshtastic.feature.messaging.wrapSelectionWithLink
T8b949e/**
* A row of markdown formatting actions (bold, italic, strikethrough, code, link) that mutate [state] in place. A
* collapsed cursor inserts an empty delimiter pair; a non-empty selection is wrapped or, if already wrapped, toggled
* off. The link action opens a URL-entry dialog, or unwraps a selected `[label](url)` back to its label.
*/
Tf0883e@Composable
Tff7b72internal Tff7b72fun Td2a8ffFormattingToolbarTb4b4b4(Te6edf3stateTb4b4b4: Te6edf3TextFieldStateTb4b4b4, Te6edf3modifierTb4b4b4: Te6edf3Modifier Tff7b72= Te6edf3ModifierTb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3showLinkDialog Tff7b72by Te6edf3remember Tb4b4b4{ Te6edf3mutableStateOfTb4b4b4(Tff7b72falseTb4b4b4) Tb4b4b4}
Tff7b72var Te6edf3pendingLinkRange Tff7b72by Te6edf3remember Tb4b4b4{ Te6edf3mutableStateOfTff7b72<Te6edf3TextRange?Tff7b72>Tb4b4b4(Tff7b72nullTb4b4b4) Tb4b4b4}
Tff7b72fun Td2a8ffapplyEditTb4b4b4(Te6edf3mutateTb4b4b4: Tb4b4b4(Tffa657StringTb4b4b4, Te6edf3TextRangeTb4b4b4) Tff7b72-Tff7b72> Te6edf3FormattingResult?Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3text Tff7b72= Te6edf3stateTb4b4b4.Te6edf3textTb4b4b4.Te6edf3toStringTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3result Tff7b72= Te6edf3mutateTb4b4b4(Te6edf3textTb4b4b4, Te6edf3stateTb4b4b4.Te6edf3selectionTb4b4b4) Tff7b72?: Tff7b72return
Te6edf3stateTb4b4b4.Te6edf3edit Tb4b4b4{
Te6edf3replaceTb4b4b4(T79c0ff0Tb4b4b4, Te6edf3lengthTb4b4b4, Te6edf3resultTb4b4b4.Te6edf3textTb4b4b4)
Te6edf3selection Tff7b72= Te6edf3resultTb4b4b4.Te6edf3selection
Tb4b4b4}
Tb4b4b4}
Tff7b72fun Td2a8ffonStyleTb4b4b4(Te6edf3styleTb4b4b4: Te6edf3InlineStyleTb4b4b4) Tff7b72= Te6edf3applyEdit Tb4b4b4{ Te6edf3textTb4b4b4, Te6edf3selection Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3selectionTb4b4b4.Te6edf3collapsedTb4b4b4) Te6edf3insertDelimitersTb4b4b4(Te6edf3textTb4b4b4, Te6edf3selectionTb4b4b4.Te6edf3minTb4b4b4, Te6edf3styleTb4b4b4) Tff7b72else Te6edf3wrapSelectionTb4b4b4(Te6edf3textTb4b4b4, Te6edf3selectionTb4b4b4, Te6edf3styleTb4b4b4)
Tb4b4b4}
Tff7b72fun Td2a8ffonLinkTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3text Tff7b72= Te6edf3stateTb4b4b4.Te6edf3textTb4b4b4.Te6edf3toStringTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3selection Tff7b72= Te6edf3stateTb4b4b4.Te6edf3selection
Tff7b72val Te6edf3selected Tff7b72= Te6edf3textTb4b4b4.Te6edf3substringTb4b4b4(Te6edf3selectionTb4b4b4.Te6edf3minTb4b4b4, Te6edf3selectionTb4b4b4.Te6edf3maxTb4b4b4)
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3selectionTb4b4b4.Te6edf3collapsed Tff7b72&Tff7b72& Te6edf3isMarkdownLinkTb4b4b4(Te6edf3selectedTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3applyEdit Tb4b4b4{ Te6edf3_Tb4b4b4, Te6edf3_ Tff7b72-Tff7b72> Te6edf3unwrapLinkTb4b4b4(Te6edf3textTb4b4b4, Te6edf3selectionTb4b4b4) Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3pendingLinkRange Tff7b72= Te6edf3selection
Te6edf3showLinkDialog Tff7b72= Tff7b72true
Tb4b4b4}
Tb4b4b4}
Te6edf3RowTb4b4b4(Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4, Te6edf3horizontalArrangement Tff7b72= Te6edf3ArrangementTb4b4b4.Te6edf3spacedByTb4b4b4(T79c0ff2.Te6edf3dpTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3FormatButtonTb4b4b4(Te6edf3MeshtasticIconsTb4b4b4.Te6edf3BoldTb4b4b4, Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3format_boldTb4b4b4)Tb4b4b4) Tb4b4b4{ Te6edf3onStyleTb4b4b4(Te6edf3InlineStyleTb4b4b4.Te6edf3BoldTb4b4b4) Tb4b4b4}
Te6edf3FormatButtonTb4b4b4(Te6edf3MeshtasticIconsTb4b4b4.Te6edf3ItalicTb4b4b4, Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3format_italicTb4b4b4)Tb4b4b4) Tb4b4b4{ Te6edf3onStyleTb4b4b4(Te6edf3InlineStyleTb4b4b4.Te6edf3ItalicTb4b4b4) Tb4b4b4}
Te6edf3FormatButtonTb4b4b4(Te6edf3MeshtasticIconsTb4b4b4.Te6edf3StrikethroughTb4b4b4, Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3format_strikethroughTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3onStyleTb4b4b4(Te6edf3InlineStyleTb4b4b4.Te6edf3StrikethroughTb4b4b4)
Tb4b4b4}
Te6edf3FormatButtonTb4b4b4(Te6edf3MeshtasticIconsTb4b4b4.Te6edf3CodeTb4b4b4, Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3format_codeTb4b4b4)Tb4b4b4) Tb4b4b4{ Te6edf3onStyleTb4b4b4(Te6edf3InlineStyleTb4b4b4.Te6edf3CodeTb4b4b4) Tb4b4b4}
Te6edf3FormatButtonTb4b4b4(Te6edf3MeshtasticIconsTb4b4b4.Te6edf3LinkTb4b4b4, Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3format_linkTb4b4b4)Tb4b4b4) Tb4b4b4{ Te6edf3onLinkTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3showLinkDialogTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3range Tff7b72= Te6edf3pendingLinkRange
Te6edf3LinkDialogTb4b4b4(
Te6edf3onDismiss Tff7b72= Tb4b4b4{
Te6edf3showLinkDialog Tff7b72= Tff7b72false
Te6edf3pendingLinkRange Tff7b72= Tff7b72null
Tb4b4b4}Tb4b4b4,
Te6edf3onConfirm Tff7b72= Tb4b4b4{ Te6edf3url Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3range Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Te6edf3applyEdit Tb4b4b4{ Te6edf3textTb4b4b4, Te6edf3_ Tff7b72-Tff7b72> Te6edf3wrapSelectionWithLinkTb4b4b4(Te6edf3textTb4b4b4, Te6edf3rangeTb4b4b4, Te6edf3urlTb4b4b4) Tb4b4b4}
Te6edf3showLinkDialog Tff7b72= Tff7b72false
Te6edf3pendingLinkRange Tff7b72= Tff7b72null
Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tf0883e@Composable
Tff7b72private Tff7b72fun Td2a8ffFormatButtonTb4b4b4(Te6edf3iconTb4b4b4: Te6edf3ImageVectorTb4b4b4, Te6edf3labelTb4b4b4: Tffa657StringTb4b4b4, Te6edf3onClickTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Te6edf3IconButtonTb4b4b4(Te6edf3onClick Tff7b72= Te6edf3onClickTb4b4b4) Tb4b4b4{ Te6edf3IconTb4b4b4(Te6edf3imageVector Tff7b72= Te6edf3iconTb4b4b4, Te6edf3contentDescription Tff7b72= Te6edf3labelTb4b4b4) Tb4b4b4}
Tb4b4b4}
Tf0883e@Composable
Tff7b72private Tff7b72fun Td2a8ffLinkDialogTb4b4b4(Te6edf3onDismissTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4, Te6edf3onConfirmTb4b4b4: Tb4b4b4(Tffa657StringTb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3url Tff7b72by Te6edf3remember Tb4b4b4{ Te6edf3mutableStateOfTb4b4b4(Ta5d6ff"Ta5d6ff"Tb4b4b4) Tb4b4b4}
Te6edf3AlertDialogTb4b4b4(
Te6edf3onDismissRequest Tff7b72= Te6edf3onDismissTb4b4b4,
Te6edf3title Tff7b72= Tb4b4b4{ Te6edf3TextTb4b4b4(Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3insert_link_titleTb4b4b4)Tb4b4b4) Tb4b4b4}Tb4b4b4,
Te6edf3text Tff7b72= Tb4b4b4{
Te6edf3OutlinedTextFieldTb4b4b4(
Te6edf3value Tff7b72= Te6edf3urlTb4b4b4,
Te6edf3onValueChange Tff7b72= Tb4b4b4{ Te6edf3url Tff7b72= Tffa657it Tb4b4b4}Tb4b4b4,
Te6edf3singleLine Tff7b72= Tff7b72trueTb4b4b4,
Te6edf3label Tff7b72= Tb4b4b4{ Te6edf3TextTb4b4b4(Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3insert_link_messageTb4b4b4)Tb4b4b4) Tb4b4b4}Tb4b4b4,
Te6edf3placeholder Tff7b72= Tb4b4b4{ Te6edf3TextTb4b4b4(Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3insert_link_url_hintTb4b4b4)Tb4b4b4) Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Tb4b4b4}Tb4b4b4,
Te6edf3confirmButton Tff7b72= Tb4b4b4{
Te6edf3TextButtonTb4b4b4(Te6edf3onClick Tff7b72= Tb4b4b4{ Te6edf3onConfirmTb4b4b4(Te6edf3urlTb4b4b4) Tb4b4b4}Tb4b4b4, Te6edf3enabled Tff7b72= Te6edf3urlTb4b4b4.Te6edf3isNotBlankTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3TextTb4b4b4(Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3insertTb4b4b4)Tb4b4b4)
Tb4b4b4}
Tb4b4b4}Tb4b4b4,
Te6edf3dismissButton Tff7b72= Tb4b4b4{ Te6edf3TextButtonTb4b4b4(Te6edf3onClick Tff7b72= Te6edf3onDismissTb4b4b4) Tb4b4b4{ Te6edf3TextTb4b4b4(Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3cancelTb4b4b4)Tb4b4b4) Tb4b4b4} Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.06s